<!--
<div class="row border-bottom">
  <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
    <div class="navbar-header">
      <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
      <form role="search" class="navbar-form-custom" action="{:url('User/index')}">
        <div class="form-group">
          <input type="text" placeholder="输入用户邮箱" class="form-control" name="key" id="top-search">
          <input type="hidden" class="form-control" name="type" value="email">
        </div>
      </form>
    </div>
    <ul class="nav navbar-top-links navbar-right">

      <li>
        <a href="http://www.{:config('app.url_domain_root')}" target="_blank">
          <i class="fa fa-home"></i> 返回前台
        </a>
      </li>
      <li>
        <a href="{:url('Login/logout')}">
          <i class="fa fa-sign-out"></i> 退出
        </a>
      </li>

    </ul>

  </nav>
</div>
-->


<div class="row border-bottom">
    <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header"><a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
            <form role="search" class="navbar-form-custom" method="get" action="{:url('User/index')}" >
                <div class="form-group">
                    <input type="hidden" name="type" value="email"/>
                    <input type="text" placeholder="请输入您需要查找的内容…" class="form-control" name="key" id="top-search" autocomplete="off">
                </div>
            </form>
            <script>
                $('form[role=search]').submit(function () {
                    var _this = $(this);
                    var input = _this.serialize();
                    var url = _this.attr('action') + '?' + input;
                    var menuName = _this.data('menu-name');//不支持menuName驼峰定义
                    menuName = typeof menuName == 'undefined' ? "搜索 \"" + _this.find("input[name=key]").val() + "\"" : menuName;

                    window.addMenuTab(url, menuName, 0);

                    _this.find("input[name=key]").val("");
                    return false;
                });
            </script>
        </div>

        <ul class="nav navbar-top-links navbar-right">
            <li>
                <a href="{:url('frontend/Index/index', [], true, get_config('domain_name'))}" target="_blank">
                    <i class="fa fa-home"></i> 网站前台
                </a>
            </li>

            <!--
            <li class="dropdown">
              <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
                <i class="fa fa-envelope"></i> <span class="label label-warning">16</span>
              </a>
              <ul class="dropdown-menu dropdown-messages">
                <li class="m-t-xs">
                  <div class="dropdown-messages-box">
                    <a href="profile.html" class="pull-left">
                      <img alt="image" class="img-circle" src="__PUBLIC__/static/admin/img/a1.jpg">
                    </a>
                    <div class="media-body">
                      <small class="pull-right">46小时前</small>
                      <strong>小四</strong> 这个在日本投降书上签字的军官，建国后一定是个不小的干部吧？
                      <br>
                      <small class="text-muted">3天前 2014.11.8</small>
                    </div>
                  </div>
                </li>
                <li class="divider"></li>
                <li>
                  <div class="dropdown-messages-box">
                    <a href="profile.html" class="pull-left">
                      <img alt="image" class="img-circle" src="__PUBLIC__/static/admin/img/a3.jpg">
                    </a>
                    <div class="media-body ">
                      <small class="pull-right text-navy">25小时前</small>
                      <strong>国民岳父</strong> 如何看待“男子不满自己爱犬被称为狗，刺伤路人”？——这人比犬还凶
                      <br>
                      <small class="text-muted">昨天</small>
                    </div>
                  </div>
                </li>
                <li class="divider"></li>
                <li>
                  <div class="text-center link-block">
                    <a class="J_menuItem" href="mailbox.html">
                      <i class="fa fa-envelope"></i> <strong> 查看所有消息</strong>
                    </a>
                  </div>
                </li>
              </ul>
            </li>
            -->

            <li class="dropdown" id="messages">
                <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
                    <i class="fa fa-bell"></i> <span class="label label-primary" id="totalMsgCount">0</span>
                </a>
                <ul class="dropdown-menu dropdown-alerts" id="msgContainer">
                </ul>
            </li>
            <!--
            <li class="hidden-xs">
              <a href="#" class="J_menuItem" data-index="0"><i class="fa fa-cart-arrow-down"></i> 购买</a>
            </li>
            -->
            <li class="hidden-xs">
                <a href="{:url('admin/Sign/logout')}" class="J_tabExit" data-index="1"><i class="fa fa fa-sign-out"></i> 退出</a>
            </li>
            <!--
            <li class="dropdown hidden-xs">
              <a class="right-sidebar-toggle" aria-expanded="false">
                <i class="fa fa-tasks"></i> 主题
              </a>
            </li>
            -->
        </ul>
    </nav>
</div>

<script type="text/html" id="systemTemplate">
    <li>
        <a class="J_menuItem" href="{:url('Article/systemList')}">
            <div>
                <i class="fa fa-bell"></i> 您有{{d.count}}条未读系统消息
                <span class="pull-right text-muted small">{{d.time}}</span>
            </div>
        </a>
    </li>
</script>
<script type="text/html" id="mailTemplate">
    <li>
        <a class="J_menuItem" href="{:url('admin/Message/mailList')}">
            <div>
                <i class="fa fa-envelope"></i> 您有{{d.count}}条未读站内消息
                <span class="pull-right text-muted small">{{d.time}}</span>
            </div>
        </a>
    </li>
</script>
<script type="commentTemplate" id="commentTemplate">
    <li>
        <a class="J_menuItem" href="{:url('Article/commentList')}" data-tab-name="评论管理">
            <div>
                <i class="fa fa-comments"></i> 您有{{d.count}}条新回复
                <span class="pull-right text-muted small">{{d.time}}</span>
            </div>
        </a>
    </li>
</script>
<script>
    function messageHandler() {
        $.ajax({
            url: '{:url("admin/Message/index")}',
            type: 'get',
            async: true,
            dataType: 'json',
            success: function (response) {
                if (response.code != 1) {
                    return;
                }
                var data = response.data;
                var totalMsgCount = data["totalMsgCount"];
                $("#totalMsgCount").html(totalMsgCount);
                $("#msgContainer").html("");
                if (totalMsgCount == 0) {
                    $("#msgContainer").hide();
                    return;
                }

                var systemMsg = data["systemMsg"];
                var commentMsg = data["commentMsg"];
                var mailMsg = data["mailMsg"];
                //$("#msgContainer").show();

                var messageHtmls = [];
                if (systemMsg.count > 0) {
                    var html = laytpl($('#systemTemplate').html()).render(systemMsg);
                    messageHtmls.push(html);
                }
                if (commentMsg.count > 0) {
                    var html = laytpl($('#commentTemplate').html()).render(commentMsg);
                    messageHtmls.push(html);
                }
                if (mailMsg.count > 0) {
                    var html = laytpl($('#mailTemplate').html()).render(mailMsg);
                    messageHtmls.push(html);
                }
                var html = messageHtmls.join("<li class=\"divider\"></li>");
                $("#msgContainer").append(html);
            },
            error: function () {
            }
        });

    }

    $(function() {

        setTimeout(function () {
            messageHandler();
        }, 2000);
        setInterval(messageHandler, 30000); //消息定时器
    });

</script>